# use normal make for this Makefile
#
# Makefile for building user programs to run on top of Nachos
#
# Several things to be aware of:
#
#    Nachos assumes that the location of the program startup routine (the
# 	location the kernel jumps to when the program initially starts up)
#       is at location 0.  This means: start.o must be the first .o passed 
# 	to ld, in order for the routine "Start" to be loaded at location 0
#

# If you are running on SunOS 5.x machines, uncomment the next line
GCCDIR = /auto/home-scf-22/csci402/testgnu/decstation-ultrix/bin/
LDFLAGS = -T newscript -N
ASFLAGS = -mips1
CPPFLAGS = $(INCDIR)

# if you aren't cross-compiling:
# GCCDIR =
# LDFLAGS = -N -T 0
# ASFLAGS =
# CPPFLAGS = -P $(INCDIR)


CC = $(GCCDIR)gcc
AS = $(GCCDIR)as
LD = $(GCCDIR)ld
CPP = $(GCCDIR)cpp

INCDIR =-I../userprog -I../threads
CFLAGS = -G 0 -c $(INCDIR)

all: halt matmult sort testfiles multiProA multiProB fork_exec_test lock_CV_test doctorOffice twoDoctorOffice doctorOfficeTest doctorOfficeTest1 doctorOfficeTest2 multiMatmult multiSort network_test

start.o: start.s ../userprog/syscall.h
	$(CPP) $(CPPFLAGS) start.s > strt.s
	$(AS) $(ASFLAGS) -o start.o strt.s
	rm strt.s

halt.o: halt.c
	$(CC) $(CFLAGS) -c halt.c
halt: halt.o start.o
	$(LD) $(LDFLAGS) start.o halt.o -o halt.coff
	../bin/coff2noff halt.coff halt

sort.o: sort.c
	$(CC) $(CFLAGS) -c sort.c
sort: sort.o start.o
	$(LD) $(LDFLAGS) start.o sort.o -o sort.coff
	../bin/coff2noff sort.coff sort

matmult.o: matmult.c
	$(CC) $(CFLAGS) -c matmult.c
matmult: matmult.o start.o
	$(LD) $(LDFLAGS) start.o matmult.o -o matmult.coff
	../bin/coff2noff matmult.coff matmult

testfiles.o: testfiles.c
	$(CC) $(CFLAGS) -c testfiles.c
testfiles: testfiles.o start.o
	$(LD) $(LDFLAGS) start.o testfiles.o -o testfiles.coff
	../bin/coff2noff testfiles.coff testfiles
multiProA.o: multiProA.c
	$(CC) $(CFLAGS) -c multiProA.c
multiProA: multiProA.o start.o
	$(LD) $(LDFLAGS) start.o multiProA.o -o multiProA.coff
	../bin/coff2noff multiProA.coff multiProA

multiProB.o: multiProB.c
	$(CC) $(CFLAGS) -c multiProB.c
multiProB: multiProB.o start.o
	$(LD) $(LDFLAGS) start.o multiProB.o -o multiProB.coff
	../bin/coff2noff multiProB.coff multiProB

fork_exec_test.o: fork_exec_test.c
	$(CC) $(CFLAGS) -c fork_exec_test.c
fork_exec_test: fork_exec_test.o start.o
	$(LD) $(LDFLAGS) start.o fork_exec_test.o -o fork_exec_test.coff
	../bin/coff2noff fork_exec_test.coff fork_exec_test

lock_CV_test.o: lock_CV_test.c userlib.h
	$(CC) $(CFLAGS) -c lock_CV_test.c
lock_CV_test: lock_CV_test.o start.o
	$(LD) $(LDFLAGS) start.o lock_CV_test.o -o lock_CV_test.coff
	../bin/coff2noff lock_CV_test.coff lock_CV_test

doctorOffice.o: doctorOffice.c userlib.h
	$(CC) $(CFLAGS) -c doctorOffice.c
doctorOffice: doctorOffice.o start.o
	$(LD) $(LDFLAGS) start.o doctorOffice.o -o doctorOffice.coff
	../bin/coff2noff doctorOffice.coff doctorOffice

twoDoctorOffice.o: twoDoctorOffice.c
	$(CC) $(CFLAGS) -c twoDoctorOffice.c
twoDoctorOffice: twoDoctorOffice.o start.o
	$(LD) $(LDFLAGS) start.o twoDoctorOffice.o -o twoDoctorOffice.coff
	../bin/coff2noff twoDoctorOffice.coff twoDoctorOffice

doctorOfficeTest.o: doctorOfficeTest.c userlib.h
	$(CC) $(CFLAGS) -c doctorOfficeTest.c
doctorOfficeTest: doctorOfficeTest.o start.o
	$(LD) $(LDFLAGS) start.o doctorOfficeTest.o -o doctorOfficeTest.coff
	../bin/coff2noff doctorOfficeTest.coff doctorOfficeTest

doctorOfficeTest1.o: doctorOfficeTest1.c userlib.h
	$(CC) $(CFLAGS) -c doctorOfficeTest1.c
doctorOfficeTest1: doctorOfficeTest1.o start.o
	$(LD) $(LDFLAGS) start.o doctorOfficeTest1.o -o doctorOfficeTest1.coff
	../bin/coff2noff doctorOfficeTest1.coff doctorOfficeTest1

doctorOfficeTest2.o: doctorOfficeTest2.c userlib.h
	$(CC) $(CFLAGS) -c doctorOfficeTest2.c
doctorOfficeTest2: doctorOfficeTest2.o start.o
	$(LD) $(LDFLAGS) start.o doctorOfficeTest2.o -o doctorOfficeTest2.coff
	../bin/coff2noff doctorOfficeTest2.coff doctorOfficeTest2

multiMatmult.o: multiMatmult.c
	$(CC) $(CFLAGS) -c multiMatmult.c
multiMatmult: multiMatmult.o start.o
	$(LD) $(LDFLAGS) start.o multiMatmult.o -o multiMatmult.coff
	../bin/coff2noff multiMatmult.coff multiMatmult

multiSort.o: multiSort.c
	$(CC) $(CFLAGS) -c multiSort.c
multiSort: multiSort.o start.o
	$(LD) $(LDFLAGS) start.o multiSort.o -o multiSort.coff
	../bin/coff2noff multiSort.coff multiSort

network_test.o: network_test.c userlib.h
	$(CC) $(CFLAGS) -c network_test.c
network_test: network_test.o start.o
	$(LD) $(LDFLAGS) start.o network_test.o -o network_test.coff
	../bin/coff2noff network_test.coff network_test

clean:
	rm -f *.o *.coff
